package com.frcdi.qms.web.controller.system;

import com.frcdi.qms.common.annotation.Log;
import com.frcdi.qms.common.config.QmsConfig;
import com.frcdi.qms.common.core.controller.BaseController;
import com.frcdi.qms.common.core.domain.AjaxResult;
import com.frcdi.qms.common.core.page.TableDataInfo;
import com.frcdi.qms.common.enums.BusinessType;
import com.frcdi.qms.common.utils.file.FileUploadUtils;
import com.frcdi.qms.common.utils.file.FileUtils;
import com.frcdi.qms.common.utils.poi.ExcelUtil;
import com.frcdi.qms.system.domain.SysConfig;
import com.frcdi.qms.system.domain.SysEmail;
import com.frcdi.qms.system.service.IEmailService;
import com.frcdi.qms.system.service.ISysConfigService;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 邮件发送 信息操作处理
 *
 * @author Mr.Han
 * @create 2024-5-14 10:20:08
 */
@RestController
@Api(tags = "参数配置")
@RequestMapping("/system/email")
public class SysEmailController extends BaseController
{
    @Autowired
    private IEmailService  emailService;

    /**
     * 发送邮件
     */
    @Log(title = "发送邮件", businessType = BusinessType.INSERT)
    @ApiOperation("发送邮件")
    @PreAuthorize("@ss.hasPermi('system:email:list')")
    @PostMapping("/sendTo")
    public AjaxResult sendTo(@RequestBody SysEmail email){
        try
        {
            /*// 上传文件路径
            String uploadPath = QmsConfig.getUploadPath();
            email.setFileName(email.getFile().getOriginalFilename());
            // 上传并返回新文件名称
            String upload = FileUploadUtils.upload(uploadPath, email.getFile());
            String filePath = QmsConfig.getProfile() + upload.split("profile")[1];
             emailService.sendAttachmentMail(email.getSendTo(),email.getTitle(),email.getContent(),filePath,email.getFileList());
     */
            emailService.sendAttachmentMail(email.getSendTo(),email.getTitle(), email.getContent(), email.getFileList());
            AjaxResult ajax = AjaxResult.success();
            // ajax.put("message1", email.getFileName());
            ajax.put("message", "发送成功");
            return ajax;
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }

    }



}
